use std::ops::Add;
#[derive(Debug,Clone,Copy)]
struct Name<'a>{
    name:&'a str
}

impl<'a> Add for Name<'a>{
    type Output = Name<'a>;
    fn add(self, other: Self) -> Self {
        let tmp=format!("{} {}",self.name,other.name);
        //Box::leak的作用是 将堆上的内存转换为 'static 生命周期的引用
        let leaked_str: &'static str = Box::leak(tmp.into_boxed_str());
        Self{name: leaked_str }
    }
}

fn main() {
    let name1 = Name{name:"lu"};
    let name2 = Name{name:" mula"};
    let name3=name1+name2;
    println!("name1={:?},name2={:?}", name1,name2);
    println!("name3={:?}", name3);

    let name4=String::from("lu");
    let name5=String::from("lu");
    let name6=add(name4,name5);
    println!("name6={:?}", name6);
}

fn add(name1:String,name2:String)->String{
    format!("{} {}",name1,name2)
}